
#include "Test.hpp"


/**
 * 模块ID
 */
PetStruct::PetStruct() {
	id = 0 ;
	listLength = 0 ;
	privateListLength = 0 ;
	privateList = NULL ;
	name = "" ;
} ;

uint32_t PetStruct::listMaxLength() { return this->privateListLength ; }
string* PetStruct::list() { return this->privateList ; }
void PetStruct::malloclist( uint32_t length ) { 
	if( this->privateList ) delete[] this->privateList ;
	this->listLength = length ;
	this->privateListLength = length ;
	this->privateList = new string[length] ;
}

PetStruct::~PetStruct() {
	if( privateList ) delete[] privateList ;
} ;

CMsgTyped* PetStruct::Serialize( CMsgTyped * msgTyped ) {
	msgTyped->SetInt( id ) ;
	{
		size_t realLength ; 
		if( listLength > privateListLength ) {
			printf( "ERROR --> [%s:%d] 越界访问[%s]\n" , __FILE__ , __LINE__ , "privateList" ) ;
			realLength = privateListLength ;
		} else {
			realLength = listLength ;
		}
		msgTyped->SetInt( realLength ) ;
		for( size_t i = 0 ; i < realLength ; ++i ) {
	msgTyped->SetString( privateList[i].c_str( ) ) ;
		}
	}
	msgTyped->SetString( name.c_str( ) ) ;
	return msgTyped ;
} ;

CMsgTyped* PetStruct::Unserialize( CMsgTyped* msgTyped ) {
	id = msgTyped->IntVal() ;
	privateListLength = msgTyped->IntVal( ) ;
	listLength = privateListLength ;
	privateList = new string[privateListLength] ;
	for( size_t i = 0 ; i < privateListLength ; ++i ) {
	privateList[i] = msgTyped->StringVal() ;
	}
	name = msgTyped->StringVal() ;
	return msgTyped ;
} ;

BagStruct::BagStruct() {
	index = 0 ;
	id = 0 ;
	petLength = 0 ;
	privatePetLength = 0 ;
	privatePet = NULL ;
	name = "" ;
} ;

uint32_t BagStruct::petMaxLength() { return this->privatePetLength ; }
PetStruct* BagStruct::pet() { return this->privatePet ; }
void BagStruct::mallocpet( uint32_t length ) { 
	if( this->privatePet ) delete[] this->privatePet ;
	this->petLength = length ;
	this->privatePetLength = length ;
	this->privatePet = new PetStruct[length] ;
}

BagStruct::~BagStruct() {
	if( privatePet ) delete[] privatePet ;
} ;

CMsgTyped* BagStruct::Serialize( CMsgTyped * msgTyped ) {
	msgTyped->SetInt( index ) ;
	msgTyped->SetInt( id ) ;
	{
		size_t realLength ; 
		if( petLength > privatePetLength ) {
			printf( "ERROR --> [%s:%d] 越界访问[%s]\n" , __FILE__ , __LINE__ , "privatePet" ) ;
			realLength = privatePetLength ;
		} else {
			realLength = petLength ;
		}
		msgTyped->SetInt( realLength ) ;
		for( size_t i = 0 ; i < realLength ; ++i ) {
	privatePet[i].Serialize( msgTyped ) ;
		}
	}
	msgTyped->SetString( name.c_str( ) ) ;
	return msgTyped ;
} ;

CMsgTyped* BagStruct::Unserialize( CMsgTyped* msgTyped ) {
	index = msgTyped->IntVal() ;
	id = msgTyped->IntVal() ;
	privatePetLength = msgTyped->IntVal( ) ;
	petLength = privatePetLength ;
	privatePet = new PetStruct[privatePetLength] ;
	for( size_t i = 0 ; i < privatePetLength ; ++i ) {
	privatePet[i].Unserialize( msgTyped ) ;
	}
	name = msgTyped->StringVal() ;
	return msgTyped ;
} ;

const uint16_t GetInfo::messageId = 0 ;
GetInfo::GetInfo() {
	id = 0 ;
	name = "" ;
	bagLength = 0 ;
	privateBagLength = 0 ;
	privateBag = NULL ;
	level = 0 ;
} ;

uint32_t GetInfo::bagMaxLength() { return this->privateBagLength ; }
BagStruct* GetInfo::bag() { return this->privateBag ; }
void GetInfo::mallocbag( uint32_t length ) { 
	if( this->privateBag ) delete[] this->privateBag ;
	this->bagLength = length ;
	this->privateBagLength = length ;
	this->privateBag = new BagStruct[length] ;
}

GetInfo::~GetInfo() {
	if( privateBag ) delete[] privateBag ;
} ;

CMsgTyped* GetInfo::Unserialize( CMsgTyped* msgTyped ) {
	id = msgTyped->IntVal() ;
	pet.Unserialize( msgTyped ) ;
	name = msgTyped->StringVal() ;
	privateBagLength = msgTyped->IntVal( ) ;
	bagLength = privateBagLength ;
	privateBag = new BagStruct[privateBagLength] ;
	for( size_t i = 0 ; i < privateBagLength ; ++i ) {
	privateBag[i].Unserialize( msgTyped ) ;
	}
	level = msgTyped->IntVal() ;
	return msgTyped ;
} ;

const uint16_t SendInfo::messageId = 0 ;

SendInfo::SendInfo() {
	id = 0 ;
	name = "" ;
	bagLength = 0 ;
	privateBagLength = 0 ;
	privateBag = NULL ;
	level = 0 ;
} ;

uint32_t SendInfo::bagMaxLength() { return this->privateBagLength ; }
BagStruct* SendInfo::bag() { return this->privateBag ; }
void SendInfo::mallocbag( uint32_t length ) { 
	if( this->privateBag ) delete[] this->privateBag ;
	this->bagLength = length ;
	this->privateBagLength = length ;
	this->privateBag = new BagStruct[length] ;
}

SendInfo::~SendInfo() {
	if( privateBag ) delete[] privateBag ;
} ;

CMsgTyped* SendInfo::Serialize( CMsgTyped * msgTyped ) {
	msgTyped->SetInt( id ) ;
	pet.Serialize( msgTyped ) ;
	msgTyped->SetString( name.c_str( ) ) ;
	{
		size_t realLength ; 
		if( bagLength > privateBagLength ) {
			printf( "ERROR --> [%s:%d] 越界访问[%s]\n" , __FILE__ , __LINE__ , "privateBag" ) ;
			realLength = privateBagLength ;
		} else {
			realLength = bagLength ;
		}
		msgTyped->SetInt( realLength ) ;
		for( size_t i = 0 ; i < realLength ; ++i ) {
	privateBag[i].Serialize( msgTyped ) ;
		}
	}
	msgTyped->SetInt( level ) ;
	return msgTyped ;
} ;

